package com.utility.project.controller;

import com.utility.project.common.base.R;
import com.utility.project.dto.YsExamAnswerDTO;
import com.utility.project.param.ExamAnswerParam;
import com.utility.project.param.QueryAnswerParam;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;
import com.utility.project.service.IYsExamAnswerService;

import java.util.List;

/**
 * @author yangzhiguo
 * @date 2024-07-29
 * @description 试题答案
 */
@Api(tags = "试题答案")
@RestController
@RequestMapping("/ysExamAnswer")
public class YsExamAnswerController {

    @Resource
    private IYsExamAnswerService ysExamAnswerService;

    @ApiOperation("根据用户名和话题id查询用户答题记录")
    @PostMapping("/queryExamAnswerList")
    public R queryById(@RequestBody QueryAnswerParam queryAnswerParam){
        List<YsExamAnswerDTO> examAnswerList = ysExamAnswerService.queryExamAnswerList(queryAnswerParam);
        return R.ok(examAnswerList);
    }

    @ApiOperation("保存用户的答题记录")
    @PostMapping("/saveExamAnswer")
    public R saveExamAnswer(@RequestBody List<ExamAnswerParam> paramList){
        Boolean res = ysExamAnswerService.saveExamAnswer(paramList);
        if(res) {
            return R.okWithMsg("用户答题记录保存成功");
        }else{
            return R.fail("用户答题记录保存失败");
        }
    }
    
}
